const connection = require("../db/connection");
const input = require("scanline");
const checkProductExist = require("./checkProductExist");
const menu = require("../UI/menu");

async function changeAll(){
    const name = await input("请输入你要修改的商品信息对应的名称:");
    checkProductExist(name);
    
    const zl = [
        "食物",
        "服装",
        "工具",
        "生活用品",
        "电子产品",
    ];

    const newname = await input("请输入该商品的新名称:");
    const price = await input("请输入该商品的新价格:");
    
    const select = await menu(zl,"请选择你的商品种类：\n");
    const kind = select.text;
    
    const num = await input("请输入该商品的新数量:");

    connection.query("update product set 名称=?,价格=?,种类=?,数量=? where 名称=?",[newname,price,kind,num,name],(error,_)=>{
        if(error){
            console.log("修改信息失败！");
            process.exit(1);
        }
        console.log("\033[33m已成功修改该商品信息!\033[0m");
    });
    connection.end();
}


module.exports = changeAll;